package bTree.LeetCode;

import javax.print.DocFlavor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 加一 {
    public int[] plusOne(int[] digits) {
        //判断是否全为9
        int len = digits.length;
        int cnt = 0;
        boolean ifAllIsNine = false;
        for (int digit : digits) {
            if (digit == 9) {
                cnt++;
            } else {
                break;
            }
        }
        if (cnt == len) {
            ifAllIsNine = true;
        }
        if (ifAllIsNine == true) {
            int[] target = new int[len + 1];
            target[0] = 1;
            for (int i = 1; i < len + 1; i++) {
                target[i] = 0;
            }
            return target;
        } else {
            digits[len-1]+=1;
            int a = len - 1;
            int path = digits[a];
            while (path == 10) {
                digits[a] = 0;
                digits[a - 1] += 1;
                path=digits[a-1];
                a--;
            }
            return digits;
        }
    }
}